package com.chuangyang.fixboxmaster.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.chuangyang.fixboxmaster.AppData;
import com.chuangyang.fixboxmaster.R;
import com.chuangyang.fixboxmaster.bean.Message;
import com.chuangyang.fixboxmaster.ui.widgets.BadgeView;

import java.util.ArrayList;

/**
 * Created by vanshu on 15/8/25 10:19.
 */
public class MessageAdapter extends BaseAdapter{

    public Context mContext;
    public  ArrayList<Message> messages;
    public MessageAdapter(Context mContext, ArrayList<Message> messages){
        this.mContext=mContext;
        this.messages=messages;
    }

    @Override
    public int getCount() {
        return messages==null ?0:messages.size();
    }

    @Override
    public Object getItem(int position) {
        return messages.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(AppData.getContext()).inflate(R.layout.message_item, parent, false);
            holder.mTitle = (TextView) convertView.findViewById(R.id.message_title);
//            holder.mSubTitle = (TextView) convertView.findViewById(R.id.message_subtitle);
            holder.mSentTime = (TextView) convertView.findViewById(R.id.message_send_time);
            holder.mIsRead = (ImageView) convertView.findViewById(R.id.bd_unread);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mSentTime.setText(messages.get(position).sentTime);
        holder.mTitle.setText(messages.get(position).title);
//        holder.mSubTitle.setText(messages.get(position).body);
        if(messages.get(position).isRead==0){
            holder.mIsRead.setVisibility(View.VISIBLE);
        }else if(messages.get(position).isRead==1){
            holder.mIsRead.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }


    public static class ViewHolder {

        public TextView mTitle;
//        public TextView mSubTitle;
        public TextView mSentTime;
        public ImageView mIsRead;
    }
}
